var express = require('express');
var router = express.Router();
const SPAWN = require('child_process').spawn;
const RL = require('readline');




/* 构建自身 */
// 如果使用pm2等热部署应该可以自动重启吧。。。
router.get('/', function (req, res, next) {
  let root_path = require('app-root-path');
console.log(root_path);
if(typeof(root_path)!='string'){
root_path = root_path.path;
}
  RL.createInterface({
    input: SPAWN('git pull', { cwd: root_path }).on('error', function (error) {
      console.log(error)
      console.log('更新失败');
    }).stdout,
    output: process.stdout,
    terminal: false
  }).on('line', function (line) {
    console.log('pull 执行结果');
    console.log(line);
    if (line) {
      //FIXME:  Error: spawn git pull ENOENT


//开始构建目录
//



    }


  }).on('close', function () {
  });

  res.write('git pull');

});

module.exports = router;
